﻿using System;

using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Data;
using System.Collections.Generic;

using SBPweb.PhotoGallery.Common;
using SBPweb.PhotoGallery.Client.Logic;

namespace SBPweb.PhotoGallery.Client
{

    public partial class ViewPage : UserControl
    {

        #region Private fields

        private AutoAdvancingGalleryList galleries;

        #endregion

        #region Constructor logic

        public ViewPage()
        {
            InitializeComponent();
        }

        public ViewPage(AutoAdvancingGalleryList galleryList)
            : this()
        {
            galleries = galleryList;
            InitializeGalleries();
        }

        private void InitializeGalleries()
        {
            //http://www.geekpedia.com/gallery/fullsize/microsoft-silverlight-wallpaper.jpg
            //ucSlideShow.Gallery = ucViewToolBar.Gallery = galleries[0];
            //ucViewToolBar.IsAutoAdvanceActive = true;
            galleries.ItemAdded += new EventHandler<OverridableList<AutoAdvancingGallery>.ItemEventArgs>(galleries_ItemAdded);
            galleries.ItemRemoved += new EventHandler<OverridableList<AutoAdvancingGallery>.ItemEventArgs>(galleries_ItemRemoved);
        }

        private void galleries_ItemAdded(object sender, OverridableList<AutoAdvancingGallery>.ItemEventArgs e)
        {
            ucSlideShow.Gallery = ucViewToolBar.Gallery = e.Item;
        }

        private void galleries_ItemRemoved(object sender, OverridableList<AutoAdvancingGallery>.ItemEventArgs e)
        {
            AutoAdvancingGallery aag = null;
            if (aag.Count > 0)
            {
                aag = galleries[e.Index - 1];
            }
            ucSlideShow.Gallery = ucViewToolBar.Gallery = aag;
        }


        #endregion

        #region Property accessors

        public Brush FillBrush
        {
            get
            {
                return rToolBar.Fill;
            }
            set
            {
                rToolBar.Fill = value;
            }
        }

        #endregion

    }

}